package com.lianxd.easybuy.servlet;

import cn.hutool.core.util.StrUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/users/*")//*通配符 匹配任意长度的字符串
public class UserServlet extends BaseServlet {
  //处理修改用户密码请求的方法
  public void updataPassword(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    System.out.println("修改用户密码");
  }

  //处理修改用户信息请求方法
  public void modifyUser(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    System.out.println("修改用户信息");
  }

  //处理用户登录注册请求fangf
  protected void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession userSession =request.getSession();
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    if (username.equals("admin") && password.equals("123456")){
      userSession.setAttribute("curName","admin");
      response.sendRedirect("/index.jsp");//重定向
    }else {
      request.setAttribute("erroMessage","用户名或密码错误");
      request.getRequestDispatcher("/login.jsp").forward(request,response);//转发
    }
  }
   //处理用户注册请求的方法
  public  void  register(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
    String username = request.getParameter("username");
    String pwd = request.getParameter("pwd");
    String repwd = request.getParameter("repwd");
    String sex = request.getParameter("sex");
    String[] hobby = request.getParameterValues("hobby");
    String problem = request.getParameter("problem");
    String answer = request.getParameter("answer");
    String introduce = request.getParameter("introduce");
  }
  //处理用户退出系统请求的方法
  public  void  logout(HttpServletRequest request,HttpServletResponse response)throws  ServletException,IOException{
    HttpSession userSession = request.getSession();
    userSession.invalidate();
    response.sendRedirect("/login.jsp");
  }
}

